package com.ecoolex.ying.space.job.scheduler;

import java.util.Calendar;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.ecoolex.framework.scheduler.Job;
import com.ecoolex.framework.scheduler.JobComponent;
import com.ecoolex.ying.space.core.manager.EstateProjectActivityCouponPackageManager;
import com.ecoolex.ying.space.entity.EstateProjectActivityCouponPackage;

@JobComponent
public class EstateProjectActivityCouponPackageCheckJob {

	private static final Logger log = LoggerFactory.getLogger(EstateProjectActivityCouponPackageCheckJob.class);

	@Autowired
	private EstateProjectActivityCouponPackageManager manager;
	
	@Job(name = "ying.space.EstateProjectActivityCouponPackageCheckJob.autoExpireCouponPackage",describe = "自动处理过期的未使用代金券包")
	public void autoExpireCouponPackage() {
		Calendar calendar = Calendar.getInstance();
		List<EstateProjectActivityCouponPackage> list = manager.listByExpireTime(calendar.getTime());
		list.forEach(couponPackage -> {
			try {
				manager.expire(couponPackage, EstateProjectActivityCouponPackageCheckJob.class.getSimpleName());
			}catch (Exception e) {
				log.error("自动处理过期的未使用代金券包，id={}",couponPackage.getId(),e);
			}
		});
	}
}
